//利用递归算法实现幂运算,pow函数幂运算当指数n大于二时,x^n=x^(n-1)*x,
//重复调用pow函数计算x^(n-1),直到n为1时，x^1=x.
#include <QCoreApplication>
#include <iostream>

long pow(int x, int n);
int main(int argc, char *argv[])
{
    using namespace std;
    QCoreApplication a(argc, argv);
    long answer;
    int x = 1;
    int n = 1;
    cout << "Enter x and n" << endl;
    cin >> x;
    cin >> n;
    while(n > 0){
        answer = pow(x, n);
        cout << "The result of " << x << "^" << n << ":"<< answer << endl;
        cout << "Enter x and n" << endl;
        cin >> x;
        cin >> n;
    }
    return a.exec();
}

long pow(int x, int n)
{
    long answer;
    if(n == 1)
        answer = x;
    else
        answer = pow(x, n-1)*x;
    return answer;
}
